package wibrst.calculators {
	import wibrst.utils.StatUtil;
	/**
	 * ...
	 * @author wibrst@qq.com
	 */
	public class MultiDblBallRewardCalc{

		static public function getCompound( nRedSelect, nBlueSelect, nRedHit, nBlueHit ):Array {
				
				var aReward = new Array;
				
				aReward[0] = calFirst(nRedSelect, nBlueSelect, nRedHit, nBlueHit);
				aReward[1] = calSecond(nRedSelect, nBlueSelect, nRedHit, nBlueHit);
				aReward[2] = calThird(nRedSelect, nBlueSelect, nRedHit, nBlueHit);
				aReward[3] = calFourth(nRedSelect, nBlueSelect, nRedHit, nBlueHit);
				aReward[4] = calFiveth(nRedSelect, nBlueSelect, nRedHit, nBlueHit);
				aReward[5] = calSixth(nRedSelect, nBlueSelect, nRedHit, nBlueHit);
				
				var nRewardIncome = getABReward( aReward[0], "A") + getABReward( aReward[1], "B")
				+ ( getNumReward(aReward[2] , 3000)
				+ getNumReward(aReward[3] , 200)
				+ getNumReward(aReward[4] , 10)
				+ getNumReward(aReward[5] , 5) );
				
				trace( "[MultiDblBallRewardCalc] getCompound", arguments, aReward, nRewardIncome );
				
				aReward[6] = nRewardIncome;
				return aReward;
		}
		
		static private function getNumReward( nCount:Number, nUnitReward:Number ):Number{
			//if ( nCount > 0 && nUnitReward > 0 ) {
			return ( nCount * nUnitReward );
		}
		
		static private function getABReward( nCount:Number, text:String ):String {
			if (nCount > 0) {
				return nCount.toString() + text + "+";
			}
			return "";
		}
		
		static private function calFirst(nRedSelect, nBlueSelect, nRedHit, nBlueHit):Number {
			var value:Number = nBlueHit * StatUtil.getCombOf(6, nRedHit) * StatUtil.getCombOf(0, nRedSelect - nRedHit);
			return value;
		}
		static private function calSecond(nRedSelect, nBlueSelect, nRedHit, nBlueHit):Number {
			var value:Number = (nBlueSelect - nBlueHit) * StatUtil.getCombOf(6, nRedHit) * StatUtil.getCombOf(0, nRedSelect - nRedHit);
			return value;
		}
		static private function calThird(nRedSelect, nBlueSelect, nRedHit, nBlueHit):Number {
			var value:Number = nBlueHit * StatUtil.getCombOf(5, nRedHit) * StatUtil.getCombOf(1, nRedSelect - nRedHit);
			return value;
		}
		
		///  D*comp(4,C)*comp(2,A-C)+(B-D)*comp(5,C)*comp(1,A-C);
		static private function calFourth(nRedSelect, nBlueSelect, nRedHit, nBlueHit):Number {
			var value:Number = nBlueHit * StatUtil.getCombOf(4, nRedHit) * StatUtil.getCombOf(2, nRedSelect - nRedHit) + (nBlueSelect - nBlueHit) * StatUtil.getCombOf(5, nRedHit) * StatUtil.getCombOf(1, nRedSelect - nRedHit);
			return value;
		}
		static private function calFiveth(nRedSelect, nBlueSelect, nRedHit, nBlueHit):Number {
			var value:Number = nBlueHit * StatUtil.getCombOf(3, nRedHit) * StatUtil.getCombOf(3, nRedSelect - nRedHit) + (nBlueSelect - nBlueHit) * StatUtil.getCombOf(4, nRedHit) * StatUtil.getCombOf(2, nRedSelect - nRedHit)
			return value;
		}
		static private function calSixth(nRedSelect, nBlueSelect, nRedHit, nBlueHit):Number { 
			var value:Number = nBlueHit * StatUtil.getCombOf(2, nRedHit) * StatUtil.getCombOf(4, nRedSelect - nRedHit) + nBlueHit * StatUtil.getCombOf(1, nRedHit) * StatUtil.getCombOf(5, nRedSelect - nRedHit) + nBlueHit * StatUtil.getCombOf(0, nRedHit) * StatUtil.getCombOf(6, nRedSelect - nRedHit);
			return value;
		}
		
	}

}